home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / gui / classactdemo.lha / ClassAct / Examples / LayoutTest.c < prev    next >
C/C++ Source or Header  |  1995-09-13  |  9KB  |  353 lines

  1. /*************************************************************************
  2.  * ClassAct Layout Example
  3.  * Copyright ⌐ 1995 Phantom Development Co.
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/icclass.h>
  11. #include <libraries/gadtools.h>
  12.  
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/text.h>
  15. #include <graphics/gfxmacros.h>
  16. #include <utility/tagitem.h>
  17.  
  18. #include <proto/intuition.h>
  19. #include <proto/graphics.h>
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22. #include <proto/diskfont.h>
  23. #include <proto/utility.h>
  24.  
  25. #include <stdio.h>
  26.  
  27. #include <gadgets/classact.h>
  28.  
  29. /*************************************************************************
  30.  * Some macro defines...
  31.  */
  32. #define max(x,y) (x > y ? x : y)
  33. #define min(x,y) (x > y ? y : x)
  34.  
  35. /*************************************************************************
  36.  * Gadget GA_ID defines for easy meaningful reference
  37.  */
  38. #define ID_BUTTON1    1L
  39. #define ID_BUTTON2    2L
  40. #define ID_BUTTON3    3L
  41. #define ID_BUTTON4    4L
  42. #define ID_BUTTON5    5L
  43. #define ID_BUTTON6    6L
  44.  
  45. /*************************************************************************
  46.  * Global ClassLibrary Bases for ClassAct
  47.  */
  48. struct ClassLibrary *ButtonBase = NULL;
  49. struct ClassLibrary *LayoutBase = NULL;
  50.  
  51. /*************************************************************************
  52.  * Global pointers to various structures we need...
  53.  */
  54.  
  55. struct Screen *Scr = NULL;
  56. struct DrawInfo *draw_info;
  57.  
  58. /*************************************************************************
  59.  * Closes all ClassAct gadget bases used in the demo
  60.  */
  61. VOID CloseClassAct(VOID)
  62. {
  63.     if(LayoutBase)
  64.     {
  65.         CloseLibrary((struct Library *)LayoutBase);
  66.         if(ButtonBase)
  67.         {
  68.             CloseLibrary((struct Library *)ButtonBase);
  69.         }
  70.     }
  71. }
  72.  
  73. /*************************************************************************
  74.  * Opens all ClassAct gadget bases used in the demo
  75.  */
  76. BOOL OpenClassAct(VOID)
  77. {
  78.     if(LayoutBase=(struct ClassLibrary *)OpenLibrary("gadgets/layout.gadget",0L))
  79.     {
  80.         if(ButtonBase=(struct ClassLibrary *)OpenLibrary("gadgets/button.gadget",0L))
  81.         {
  82.             return(TRUE);
  83.         }
  84.     }
  85.     /* Something failed to open, close down shop.
  86.      */
  87.     CloseClassAct();
  88.     return(FALSE);
  89. }
  90.  
  91. /*************************************************************************
  92.  * Main Program
  93.  */
  94. int main(argc,argv)
  95. int argc;
  96. char *argv[];
  97. {
  98.     struct Window *Win;
  99.     LONG ID;
  100.  
  101.     if(!OpenClassAct())
  102.     {
  103.         Printf("Failed opening ClassAct.\n");
  104.         return(20);
  105.     }
  106.  
  107.     if(argc > 1)
  108.         Scr = LockPubScreen(argv[1]);
  109.     else
  110.         Scr = LockPubScreen("Workbench");
  111.  
  112.     if (Scr == NULL)
  113.     {
  114.         /* Shut down, no screen lock
  115.          */ 
  116.         Printf("Failed locking public screen.\n");
  117.         CloseClassAct();
  118.         return(5);
  119.     }
  120.  
  121.     draw_info = GetScreenDrawInfo(Scr);
  122.     if(draw_info)
  123.     {
  124.         struct Gadget *gParent, *layout2, *buttonrow;
  125.  
  126.         /* In this example we will create the layout group before opening
  127.          * the window, and size the window to the minimum layout size
  128.          * returned by the LayoutLimits() function, then SetGadgetAttr()
  129.          * will be used to cause the GREL layout group to resize with the window.
  130.          */
  131.         gParent = LayoutObject,
  132.             LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  133.             LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
  134.             LAYOUT_LeftSpacing, INTERWIDTH,
  135.             LAYOUT_RightSpacing, INTERWIDTH,
  136.             LAYOUT_TopSpacing, INTERHEIGHT,
  137.             LAYOUT_BottomSpacing, INTERHEIGHT,
  138.             LAYOUT_BevelStyle, BVS_NONE,
  139.  
  140.             LAYOUT_AddChild, LayoutObject,
  141.                     LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  142.                     LAYOUT_LeftSpacing, 0,
  143.                     LAYOUT_RightSpacing, 0,
  144.                     LAYOUT_TopSpacing, 0,
  145.                     LAYOUT_BottomSpacing, 0,
  146.                     LAYOUT_AddChild, LayoutObject,
  147.                             LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  148.                             LAYOUT_LeftSpacing, INTERWIDTH,
  149.                             LAYOUT_RightSpacing, INTERWIDTH,
  150.                             LAYOUT_TopSpacing, INTERHEIGHT,
  151.                             LAYOUT_BottomSpacing, INTERHEIGHT,
  152.                             LAYOUT_BevelStyle, BVS_GROUP,
  153.                             LAYOUT_Label, "Horizontal",
  154.                             LAYOUT_LabelPlace, BVJ_TOP_CENTER,
  155.                             LAYOUT_AddChild, ButtonObject,
  156.                                     GA_ID, ID_BUTTON1,
  157.                                 End,
  158.                             LAYOUT_AddChild, ButtonObject,
  159.                                     GA_ID, ID_BUTTON2,
  160.                                 End,
  161.                             LAYOUT_AddChild, ButtonObject,
  162.                                     GA_ID, ID_BUTTON3,
  163.                                 End,
  164.                         End,
  165.  
  166.                     LAYOUT_AddChild, LayoutObject,
  167.                             LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  168.                             LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
  169.                             LAYOUT_LeftSpacing, INTERWIDTH,
  170.                             LAYOUT_RightSpacing, INTERWIDTH,
  171.                             LAYOUT_TopSpacing, INTERHEIGHT,
  172.                             LAYOUT_BottomSpacing, INTERHEIGHT,
  173.                             LAYOUT_BevelStyle, BVS_GROUP,
  174.                             LAYOUT_Label, "Vertical",
  175.                             LAYOUT_LabelPlace, BVJ_TOP_CENTER,
  176.                             LAYOUT_AddChild, ButtonObject,
  177.                                     GA_ID, ID_BUTTON4,
  178.                                 End,
  179.                             LAYOUT_AddChild, ButtonObject,
  180.                                     GA_ID, ID_BUTTON5,
  181.                                 End,
  182.                             LAYOUT_AddChild, ButtonObject,
  183.                                     GA_ID, ID_BUTTON6,
  184.                                 End,
  185.                         End,
  186.                 End,
  187.  
  188.             LAYOUT_AddChild, buttonrow = LayoutObject,
  189.                     LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  190.                     LAYOUT_VertAlignment, LAYOUT_ALIGN_BOTTOM,
  191.                     LAYOUT_LeftSpacing, INTERWIDTH,
  192.                     LAYOUT_RightSpacing, INTERWIDTH,
  193.                     LAYOUT_TopSpacing, INTERHEIGHT,
  194.                     LAYOUT_BevelStyle, BVS_SBAR_VERT,
  195.                     LAYOUT_Label, "Free, Fixed and Weighted sizes.",
  196.                     LAYOUT_LabelPlace, BVJ_TOP_CENTER,
  197.                     LAYOUT_ShrinkWrap, FALSE,
  198.                     LAYOUT_AddChild, ButtonObject,
  199.                             GA_Text, "25Kg",
  200.                         End,
  201.                         CHILD_WeightedWidth, 25,
  202.                     LAYOUT_AddChild, ButtonObject,
  203.                             GA_Text, "50Kg",
  204.                         End,
  205.                         CHILD_WeightedWidth, 50,
  206.                     LAYOUT_AddChild, ButtonObject,
  207.                             GA_Text, "75Kg",
  208.                         End,
  209.                         CHILD_WeightedWidth, 75,
  210.                     LAYOUT_AddChild, ButtonObject,
  211.                             GA_Text, "100Kg",
  212.                         End,
  213.                         CHILD_WeightedWidth, 100,
  214.                 End,
  215.                 CHILD_WeightedHeight,0,
  216.  
  217.             LAYOUT_AddChild, LayoutObject,
  218.                     LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  219.                     LAYOUT_VertAlignment, LAYOUT_ALIGN_TOP,
  220.                     LAYOUT_LeftSpacing, INTERWIDTH,
  221.                     LAYOUT_RightSpacing, INTERWIDTH,
  222.                     LAYOUT_RightSpacing, INTERWIDTH,
  223.                     LAYOUT_BottomSpacing, INTERHEIGHT,
  224.                     LAYOUT_AddChild, ButtonObject,
  225.                             GA_Text, "Free",
  226.                         End,
  227.                     LAYOUT_AddChild, ButtonObject,
  228.                             GA_Text, "Fixed",
  229.                         End,
  230.                         CHILD_WeightedWidth, 0,
  231.                     LAYOUT_AddChild, ButtonObject,
  232.                             GA_Text, "Free",
  233.                         End,
  234.                     LAYOUT_AddChild, ButtonObject,
  235.                             GA_Text, "Fixed",
  236.                         End,
  237.                         CHILD_WeightedWidth, 0,
  238.                 End,
  239.                 CHILD_WeightedHeight,0,
  240.             End;
  241.  
  242.         if (gParent)
  243.         {
  244.             struct LayoutLimits Limits;
  245.             struct TextFont *font = OpenFont( Scr->Font );
  246.  
  247.             /* Query parent layout group for min/max layout limits.
  248.              */
  249.             LayoutLimits( gParent, &Limits, font );
  250.  
  251.             CloseFont( font );
  252.  
  253.             if (Win = OpenWindowTags(NULL,
  254.                 WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  255.                     WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_SIZEGADGET,
  256.                 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
  257.                     IDCMP_GADGETUP | IDCMP_IDCMPUPDATE,
  258.                 WA_Top, 20,
  259.                 WA_Left, 20,
  260.                 WA_InnerWidth, Limits.MinWidth,
  261.                 WA_InnerHeight, Limits.MinHeight,
  262.                 WA_SmartRefresh, TRUE,
  263.                 WA_PubScreen, Scr,
  264.                 WA_Title, "ClassAct layout.gadget Example",
  265.                 WA_ScreenTitle, "ClassAct Copyright 1995 Phantom Development LLC.",
  266.                 TAG_END))
  267.             {
  268.                 ULONG wsig = 1L << Win->UserPort->mp_SigBit;
  269.                 struct IntuiMessage *msg;
  270.                 BOOL done = FALSE;
  271.  
  272.                 WORD BorderWidth = Win->BorderLeft + Win->BorderRight;
  273.                 WORD BorderHeight = Win->BorderTop + Win->BorderBottom;
  274.  
  275.                 WindowLimits(Win,
  276.                             Limits.MinWidth + BorderWidth,
  277.                             Limits.MinHeight + BorderHeight,
  278.                             Limits.MaxWidth + BorderWidth,
  279.                             Limits.MaxHeight + BorderHeight);
  280.  
  281.                 SetGadgetAttrs( gParent, NULL, NULL, 
  282.                             GA_Top, Win->BorderTop,
  283.                             GA_Left, Win->BorderLeft,
  284.                             GA_RelWidth, -BorderWidth,
  285.                             GA_RelHeight, -BorderHeight,
  286.                             ICA_TARGET, ICTARGET_IDCMP,
  287.                             TAG_END);
  288.                 
  289.                 AddGadget(Win, gParent, -1);
  290.                 RefreshGList(gParent, Win, NULL, 1);
  291.  
  292.                 while (done == FALSE)
  293.                 {
  294.                     ULONG sig = Wait(wsig | SIGBREAKF_CTRL_C);
  295.  
  296.                     if (sig & wsig)
  297.                     {
  298.                         while (msg = (struct IntuiMessage *) GetMsg(Win->UserPort))
  299.                         {
  300.                             switch (msg->Class)
  301.                             {
  302.                                 case IDCMP_CLOSEWINDOW:
  303.                                      done = TRUE;
  304.                                      break;
  305.  
  306.                                 case IDCMP_IDCMPUPDATE:
  307.                                     {
  308.                                         USHORT code;
  309.                                         if (!FindTagItem(LAYOUT_RelVerify, msg->IAddress))
  310.                                             break;
  311.                                         code = GetTagData(LAYOUT_RelCode, 0, msg->IAddress);
  312.                                         switch (GetTagData(GA_ID, 0, msg->IAddress))
  313.                                         {
  314.                                             case ID_BUTTON1:
  315.                                                 break;
  316.                                             case ID_BUTTON2:
  317.                                                 break;
  318.                                             case ID_BUTTON3:
  319.                                                 break;
  320.                                             case ID_BUTTON4:
  321.                                                 break;
  322.                                             case ID_BUTTON5:
  323.                                                 break;
  324.                                             case ID_BUTTON6:
  325.                                                 break;
  326.                                             default:
  327.                                                 break;
  328.                                         }
  329.                                     }
  330.                                     break;
  331.  
  332.                                 default:
  333.                                     break;
  334.                             }
  335.                             ReplyMsg((struct Message *) msg);
  336.                         }
  337.                     }
  338.                     else if (sig & SIGBREAKF_CTRL_C)
  339.                     {
  340.                         done = TRUE;
  341.                     }
  342.                 }
  343.                 RemoveGadget(Win, gParent);
  344.                 CloseWindow(Win);
  345.             }
  346.             DisposeObject(gParent);
  347.         }
  348.         FreeScreenDrawInfo(Win->WScreen, draw_info);
  349.     }
  350.     UnlockPubScreen(0, Scr);
  351.     CloseClassAct();
  352. }
  353.